﻿using System.Text;

namespace ArticleClientLib
{
    public static class ConsoleRedirector
    {
        /// <summary>
        /// 控制台重定向
        /// </summary>
        public static void Redirect(ConsoleTextWriter w)
        {
            Console.SetOut(w);
        }
    }

    public class ConsoleTextWriter : TextWriter
    {
        public override Encoding Encoding => Encoding.UTF8;

        Action<string> writeLn;

        public ConsoleTextWriter(Action<string> writeLn)
        {
            this.writeLn = writeLn;
        }

        public override void WriteLine(string? value)
        {
            writeLn(value?.Trim());
        }
    }

}
